<template>
  <van-pull-refresh
    v-model="isLoading"
    success-text="刷新成功"
    @refresh="onRefresh"
  >
    <div class="focus">
      <div class="focus_left">
        <InfoBoxVue
          class="info_box"
          v-for="(item, index) in list"
          :key="index"
          @click="detailInfo(item.uid, item.pid)"
        >
          <template v-slot:img>
            <van-image
              fit="contain"
              radius="6 6 0 0"
              :src="item.imageUrl"
              alt="fail"
              class="img"
            ></van-image>
          </template>
          <template v-slot:title>{{ item.title }}</template>
          <template v-slot:head_img>
            <van-image
              round
              class="head_img"
              width="20"
              height="20"
              :src="item.headUrl"
            ></van-image>
          </template>
          <template v-slot:author_name>{{ item.name }}</template>
          <template v-slot:like
            ><van-icon
              v-if="item.isactive == 'false'"
              name="like-o"
              color="red"
            ></van-icon>
            <van-icon name="like" color="red" v-else></van-icon>
          </template>
          <template v-slot:like_cnt>{{ item.likes }}</template>
        </InfoBoxVue>
      </div>
      <!-- <div class="focus_right">
        <InfoBoxVue class="info_box">
          <template v-slot:author_name> 草莓树莓 </template>
        </InfoBoxVue>
      </div> -->
    </div>
  </van-pull-refresh>
</template>

<script>
import InfoBoxVue from "../../../components/Home/InfoBox.vue";
import axios from "axios";
export default {
  data() {
    return {
      count: 0,
      isLoading: false,
      list: [],
    };
  },
  mounted() {
    this.getFocus();
  },
  created() {
    //渲染数据
    axios.get("/js/data.json").then((res) => {
      var item;
      if (!localStorage.getItem("find")) {
        item = res.data.find;
      } else {
        item = JSON.parse(localStorage.getItem("find"));
      }
      this.getFocus();
    });
  },
  components: { InfoBoxVue },
  methods: {
    onRefresh() {
      setTimeout(() => {
        // Toast('刷新成功');
        this.isLoading = false;
        this.count++;
      }, 1000);
    },
    //发现 渲染数据
    getFocus() {
      this.list = JSON.parse(localStorage.getItem("find"));
    },
    //点击事件
    detailInfo(uid, pid) {
      this.$router.push("/home/detailinfo/" + uid + "/" + pid);
    },
  },
};
</script>

<style scoped>
.focus {
  margin: 40px 10px 50px 8px;
  width: 95%;
  height: 100%;
  line-height: 20px;
  text-align: center;
  column-count: 2;
  column-gap: 7px;
}
.info_box {
  /* margin-top: 10px; */
  height: 100%;
  break-inside: avoid;
}
.img {
  width: 100%;
  border-radius: 6px 6px 0 0;
}
.head_img {
  margin-left: 10px;
  width: 20px;
  height: 20px;
  line-height: 30px;
  text-align: center;
  border-radius: 10px;
  border: 1px solid rgba(187, 187, 187, 100);
}
</style>